package com.rabbit.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.rabbit.R;

public class ButtomTagBarView extends RelativeLayout {

//    private TextView mNumView;

    private ImageView mIconView;

    private TextView mTabbarTypeNameView;

//    private ImageView mRedPoint;

    private boolean isShowRedPoint;

    private boolean isSelected;

    private int mSessionNum = 0;

    /***
     * session页面中未读信息数量的最大值
     */
    private static final int SESSION_MAX_NO_READ_COUNT = 99;

    public ButtomTagBarView(Context context) {
        super(context);
    }

    public ButtomTagBarView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public ButtomTagBarView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
//        mNumView = (TextView) findViewById(R.id.main_tag_num);
        mIconView = (ImageView) findViewById(R.id.main_tag_bar);
//        mRedPoint = (ImageView) findViewById(R.id.main_red_point);
        mTabbarTypeNameView = (TextView)findViewById(R.id.tabbar_type_name);
//        mNumView.setVisibility(View.GONE);
//        mRedPoint.setVisibility(View.GONE);
    }

    public void setTypeName(int resId){
        mTabbarTypeNameView.setText(resId);
    }

    public void setSelected() {
        setSelected(true);
    }

    public void clearSelected() {
        setSelected(false);
    }

    public boolean checkIsSelected() {
        return isSelected;
    }

    /*public void setNumViewBackground(int resId) {
        mNumView.setBackgroundResource(resId);
    }
*/
    /****
     *
     * 设置Sessionfragment页面中bar的未读信息数量 规则： <li>1.sessionNum = 0 隐藏
     * {@link ButtomTagBarView#mNumView}</li> <li>2.sessionNum>
     * {@link ButtomTagBarView#SESSION_MAX_NO_READ_COUNT}
     * 设置R.drawable.session_item_notic_read_long的资源图片</li> <li>3.设置背景 数值</li>
     * <p>
     * 改的也很无奈，不改的话上层逻辑太墨迹了.
     * </p>
     *
     * @param sessionNum session页面的未读信息数
     * @author bywyu
     */
    /*public void setSessionNum(int sessionNum) {

        if(mNumView == null){
            throw new NullPointerException("Tabbar's numView must not null!!!");
        }

//        if (sessionNum == 0) {
//            mNumView.setText("");
//            mNumView.setVisibility(GONE);
//        } else if (sessionNum > SESSION_MAX_NO_READ_COUNT) {
//            mNumView.setText("");
//            mNumView.setVisibility(VISIBLE);
//            mNumView.setBackgroundResource(R.drawable.session_item_unread_bg);
//        } else {
//            mNumView.setText(String.valueOf(sessionNum));
//            mNumView.setVisibility(VISIBLE);
//            mNumView.setBackgroundResource(R.drawable.session_item_unread_count_bg);
//        }
        this.mSessionNum = sessionNum;
    }

    public int getSessionNum() {
        return mSessionNum;
    }*/

    /*public void setNum(String num) {
        if (mNumView == null) {
            return;
        }
        if (num == null) {
            mNumView.setText("");
            mNumView.setVisibility(View.GONE);
            return;
        }
        mNumView.setText(num);
        mNumView.setVisibility(View.VISIBLE);
    }

    public String getNum() {
        if (mNumView == null) {
            return null;
        }
        return mNumView.getText().toString();
    }*/

    public void setIconRes(int id) {
        if (mIconView == null) {
            return;
        }
        mIconView.setImageResource(id);
    }

    public void setIconBitmap(Bitmap map) {
        if (mIconView == null) {
            return;
        }
        mIconView.setImageBitmap(map);
    }

    /*public void showRedPoint() {
        if (mRedPoint == null) {
            return;
        }
        mRedPoint.setVisibility(View.VISIBLE);
        isShowRedPoint = true;
    }

    public void hideRedPoint() {
        if (mRedPoint == null) {
            return;
        }
        mRedPoint.setVisibility(View.GONE);
        isShowRedPoint = false;
    }*/

    /*public boolean isShowRedPoint() {
        return isShowRedPoint;
    }*/

}
